﻿@model QuanLyGiaoVuUI.Models.BanTinGiaoVu.BanTinGiaoVuViewModel
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_blueWhaleLayout.cshtml";
}
<style>
    span {
        padding:5px;
    }
</style>

<div id="main" class="grid_12">
    <!--  start page-heading -->

    <div id="page-heading" class="box round first grid">
        <h2>Danh Sách Tin Tức</h2>
    <!-- end page-heading -->
    <div class="block">
       <table id="dstintuc" class="data display datatable">
           <tr>
               <th class="sorting">STT</th>
               <th class="sorting"><input type="checkbox" id="checkall" />#</th>
               <th class="sorting">Tiêu đề</th>
               <th class="sorting">Ngày Đăng</th>
               <th class="sorting">Chi Tiết</th>
            </tr>
               @if (Model.DanhSachBanTin != null)
               {
                   var stt=1;
                   foreach (var tintuc in Model.DanhSachBanTin)
                   {
                        <tr class="gradeA @((++stt % 2) == 0 ? "even" : "odd")">
                            <td class="odd gradeX">@(stt)</td>
                            <td class="odd gradeX"><input type="checkbox" class="checkbox" value="@tintuc.ID" /></td>
                            <td class="odd gradeX">@tintuc.TieuDe</td>
                            <td class="odd gradeX">@tintuc.NgayThem</td>
                            <td class="odd gradeX"><a href="/BanTinGiaoVu/CapNhatBanTin/@tintuc.ID">Chi Tiết</a></td>
                        </tr>
                   }
               }
       </table>
        <div>
            <input type="button" id="createNew" value="Tạo bản tin"/>
            <input type="button" id="deleteAll" value="Xoá"/>
        </div>
    </div>
</div>
</div>

<div class="clear">&nbsp;</div>

<script>
    $(document).ready(function () {
        $('#checkall').change(function () {
            var value = $(this).attr('checked');
            if (value == "checked") {
                $(".checkbox").each(function () {
                    $(this).attr("checked", "checked");
                });
            }
            else {
                    $(".checkbox").each(function () {
                        $(this).removeAttr("checked");
                    });
            }
        });
        $('#deleteAll').click(function () {
            var r = confirm("Bạn muốn xóa những thông báo này?");
            if (r == true) {
                var listID = "";
                $(".checkbox").each(function () {
                    var status = $(this).attr("checked");
                    if (status == "checked") {
                        listID += $(this).attr("value") + ",";
                    }
                });
                //alert(listID);
                $.post("/BanTinGiaoVu/DeleteBanTin", { listID: listID }, function (data) {
                    window.location = "/BanTinGiaoVu/Index";
                });
                //alert(listID);
            }
        });

        $("#createNew").click(function () {
            window.location = "/banTinGiaoVu/ThemBanTin";
        });
    });
</script>